import pandas as pd
import numpy as np
from math import pi
from scipy.fftpack import fft, ifft
import matplotlib.pyplot as plt
from scipy import signal
# from My_PCA import PCA as mypca
from sklearn.decomposition import PCA
from mpl_toolkits.mplot3d import Axes3D

if __name__ == "__main__":
    """
    从表格中将数据获取出来并做类型转换 
    """
    cols = range(10, 70)
    # print(cols)
    # dat = pd.read_csv("huxi 9.5 30.csv", usecols=cols)
    # dat = pd.read_csv("fuwocheng 6.csv", usecols=cols)
    # dat = pd.read_csv("dunqi.csv", usecols=cols)
    # dat = pd.read_csv("jingzhi.csv", usecols=cols)
    dat = pd.read_csv("handclap_breath_calap110ci.csv", usecols=cols)
    # dat = pd.read_csv("xintiao_weizhi_1_30s_10ci.csv", usecols=cols)
    # dat = pd.read_csv("zhanli_loc.csv", usecols=cols)
    # dat = pd.read_csv("xintiao_weizhi_2_30s_19ci.csv", usecols=cols)
    data = np.array(dat)
    i = 0
    amp_all = []
    for m in data:
        amp_all.append([])
        for n in m:
            amp_all[i].append(abs(complex(n)))
        i += 1
    amp_all = np.nan_to_num(np.transpose(amp_all))
    [x, y] = np.shape(amp_all)
    x = np.arange(x)
    y = np.arange(y)
    [x ,y] = np.meshgrid(x,y)

    z = amp_all.T
    print(np.shape(x))
    print(np.shape(y))
    print(np.shape(z))

    print(type(x))
    print(type(y))
    print(type(z))


    # Z = [[1 for _ in range(np.shape(Y)[0])] for _ in range(np.shape(X)[1])]
    # fig = plt.figure(1)
    # ax = Axes3D(fig)
    # ax.plot_surface(x,y,z,rstride=1,cstride=1,cmap="rainbow")
    # plt.show()
    """
       对数据进行滤波，用butter滤波器,滤波后的数据以filter标识  wn频率(Hz)/奈奎斯特频率（采样率*0.5）
       """
    fs = 100
    nyq = 0.5 * fs
    lowcut = 0.01  # 1hz
    highcut = 1 # 1.5hz
    low = lowcut / nyq
    high = highcut / nyq
    [b1, a1] = signal.butter(3, [low, high], 'band')
    amp_bandfilter_data = signal.filtfilt(b1, a1, amp_all[8])
    plt.figure(2)
    plt.plot(amp_bandfilter_data)
    plt.show()
